package com.tanhua.manager.controller;

import com.tanhua.manager.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @author liuyp
 * @date 2021/02/21
 */
@RestController
@RequestMapping("/manage")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 分页查询用户列表
     * GET /manage/users
     */
    @GetMapping("/users")
    public ResponseEntity findUserList(@RequestParam(defaultValue = "1") int page,
                                       @RequestParam(defaultValue = "10") int pagesize){

        return userService.findUserList(page, pagesize);
    }

    /**
     * 查看用户详情
     * GET /manage/users/:userID
     */
    @GetMapping("/users/{id}")
    public ResponseEntity findUserInfoById(@PathVariable("id") Long userId){
        return userService.findUserInfoById(userId);
    }

    /**
     * 分页查询某用户的动态列表
     * GET /manage/messages
     */
    @GetMapping("/messages")
    public ResponseEntity findMovementsList(@RequestParam(defaultValue = "1") int page,
                                            @RequestParam(defaultValue = "10")int pagesize,
                                            @RequestParam(required = false) Long uid,
                                            @RequestParam(required = false) Integer state){
        return userService.findMovementsList(page, pagesize, uid, state);
    }

    /**
     * 分页查询某用户的视频列表
     * GET /manage/videos
     */
    @GetMapping("/videos")
    public ResponseEntity findVideoList(@RequestParam(defaultValue = "1") int page,
                                        @RequestParam(defaultValue = "10")int pagesize,
                                        @RequestParam(required = false) Long uid){
        return userService.findVideoList(page, pagesize, uid);
    }

    /**
     * 查询动态详情
     * GET /manage/messages/:id
     */
    @GetMapping("/messages/{id}")
    public ResponseEntity findMovementById(@PathVariable("id") String publishId){
        return userService.findMovementById(publishId);
    }

    /**
     * 查询动态的评论列表
     * GET/manage/messages/comments
     */
    @GetMapping("/messages/comments")
    public ResponseEntity findMovementCommentsList(@RequestParam(defaultValue = "1") int page,
                                                   @RequestParam(defaultValue = "10")int pagesize,
                                                   String messageID){
        return userService.findMovementCommentsList(page, pagesize, messageID);
    }
}
